package com.example.whm.lib;

import android.content.Context;
import android.graphics.PointF;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.widget.Gallery;

public class CustomGallery extends Gallery {
	private GestureDetector mDetector;
    public CustomGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
       // GestureDetector detector = new GestureDetector(context, this);
     //   mDetector = detector;
        // TODO Auto-generated constructor stub
    }
 
    public CustomGallery(Context context) {
        super(context);
      //  GestureDetector detector = new GestureDetector(context, this);
      //  mDetector = detector;
        // TODO Auto-generated constructor stub
    }
 
    
    public GestureDetector getGestureDetector() {
        return mDetector;
    }

    /*@Override
    public boolean onDown(MotionEvent e) {
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
      //  LogUtil.info("json", "onSingleTapUp");
        if(listener != null) {
            listener.setOnSimpleClickListenr(getCurrentItem());
        }
        return true;
    }
    
    
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
            float distanceY) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        return false;
    }
    
    private onSimpleClickListener listener;
    
    public interface onSimpleClickListener {
        void setOnSimpleClickListenr(int position);
    }
    
    public void setOnSimpleClickListener(onSimpleClickListener listener) {
        this.listener = listener;
    }
    */
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
   /*
    	
    	
    	final float x = arg0.getRawX();
        final float y = arg0.getRawY();
        float yDistance = 0;
        float xDistance = 0;
        float mLastMotionX = 0;
        float mLastMotionY = 0;
        boolean mIsBeingDragged = false; 
        
        switch (arg0.getAction()) {  
        case MotionEvent.ACTION_DOWN:  
          //     LogUtil.verbose("json", "ACTION_DOWN");
            xDistance = yDistance = 0f;
            mLastMotionX = x;
            mLastMotionY = y;
        case MotionEvent.ACTION_MOVE:  
          //  LogUtil.verbose("json", "ACTION_MOVE, x: " + x + ", y: " + y);
            
            final float xDiff = Math.abs(x - mLastMotionX);
            final float yDiff = Math.abs(y - mLastMotionY);
            xDistance += xDiff;
            yDistance += yDiff;
            
            float dx = xDistance - yDistance;
          //  LogUtil.info("json", "ACTION_MOVE dx= " + dx + ",xDistance: " + xDistance + ", yDistance: " + yDistance);
            if (xDistance > yDistance || Math.abs(xDistance - yDistance) < 0.00001f) {
              //  LogUtil.warn("json", "ACTION_MOVE interceptor.");
                mIsBeingDragged = true;
                mLastMotionX =  x;
                mLastMotionY = y;
                getParent().requestDisallowInterceptTouchEvent(true);
            } else {
                mIsBeingDragged = false;
             
                requestDisallowInterceptTouchEvent(false);
            }
            break;  
        case MotionEvent.ACTION_UP:  
          //  LogUtil.verbose("json", "ACTION_UP");
             break;  
        case MotionEvent.ACTION_CANCEL:
         //   LogUtil.verbose("json", "ACTION_CANCEL");
         //   LogUtil.verbose("json", "mIsBeingDragged=" + mIsBeingDragged + " xDistance= " + xDistance + " y=" + yDistance);
            if(mIsBeingDragged) {
            	getParent().requestDisallowInterceptTouchEvent(false);
            }
            break;
        default:  
            break;  
        }  

    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
    	
        return super.onTouchEvent(arg0);
    }*/
 
    
    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
      
    	
    	 if(arg0.getAction() == MotionEvent.ACTION_DOWN){
         
         	x=arg0.getX();
         	y=arg0.getY();
         
         	System.out.println("onInterceptTouchEvent down  x="+x+",y="+y);
         	 getParent().requestDisallowInterceptTouchEvent(true);
         }
    	
    	 if(arg0.getAction() == MotionEvent.ACTION_MOVE){
             //此句代码是为了通知他的父ViewPager现在进行的是本控件的操作，不要对我的操作进行干扰
         	//x=arg0.getX();
         	//y=arg0.getY();
         	System.out.println("onInterceptTouchEvent move  arg0.getX()="+arg0.getX()+",arg0.getY()="+arg0.getY());
    		
         	int cur_index = getSelectedItemPosition();
    	    	int index=getAdapter().getCount()-1; 
    		 
    			if (arg0.getX()-x<-10&&Math.abs(arg0.getY()-y)<10) {
            		System.out.println("right"+(cur_index==index));
            		if (cur_index==index) {
            			 getParent().requestDisallowInterceptTouchEvent(false);
    					
    				}else{
    					
    					 getParent().requestDisallowInterceptTouchEvent(true);
    				}
    			}
            	//left
                if (arg0.getX()-x>10&&Math.abs(arg0.getY()-y)<10) {
                	System.out.println("left"+(cur_index==0));
    				if (cur_index==0) {    				
    					 getParent().requestDisallowInterceptTouchEvent(false);
    				}else{
    				
    					 getParent().requestDisallowInterceptTouchEvent(true);
    				}
    			}
         	
         	
         	
          //  getParent().requestDisallowInterceptTouchEvent(true);
         	//return true;
         }
    	 
    	 
    	 
    	 
    	 
    	 return super.onInterceptTouchEvent(arg0);
    	 
    	 
    	/*boolean bb=super.onInterceptTouchEvent(arg0);
    	if(arg0.getAction()==MotionEvent.ACTION_DOWN){
    	e=MotionEvent.obtain(arg0);
    	super.onTouchEvent(arg0);
    	}else if(arg0.getAction()==MotionEvent.ACTION_MOVE){
    	//手指触摸的大小.........这儿我设的是20像素
    	if(Math.abs(arg0.getX()-e.getX())>20 || Math.abs(arg0.getY()-e.getY())>20){
    	bb=true;
    	}
    	}
    	return bb;*/
    	 
    	 
    	 
    	 
    	 
    	 
    	
    }
    MotionEvent e;
    
    float x = 0;
	float y = 0;
	
	@Override
    public boolean onTouchEvent(MotionEvent arg0) {
       
        return super.onTouchEvent(arg0);
    }
    
    
    
}



/*

public class ChildViewPager extends ViewPager{

    public ChildViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public ChildViewPager(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    float curX = 0f;
    float downX = 0f;
    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        curX = arg0.getX();
        if(arg0.getAction() == MotionEvent.ACTION_DOWN){
            downX = curX;
        }
        int curIndex = getCurrentItem();
        if(curIndex == 0){
            if(downX <= curX){
                getParent().requestDisallowInterceptTouchEvent(false);
            }else{
                getParent().requestDisallowInterceptTouchEvent(true);
            }
        }else if(curIndex == getAdapter().getCount()-1){
            if(downX >= curX){
                getParent().requestDisallowInterceptTouchEvent(false);
            }else{
                getParent().requestDisallowInterceptTouchEvent(true);
            }
        }else{
            getParent().requestDisallowInterceptTouchEvent(true);
        }
        return super.onTouchEvent(arg0);
    }
}

*
*/








